package com.hebeu.group.service.impl;

import com.hebeu.group.mapper.OtableMapper;
import com.hebeu.group.pojo.Otable;
import com.hebeu.group.pojo.OtableExample;
import com.hebeu.group.service.TableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TableServiceImpl implements TableService {

    private OtableMapper tableMapper;

    @Autowired
    public TableServiceImpl(OtableMapper tableMapper) {
        this.tableMapper = tableMapper;
    }

    /**
     * 查询所有餐桌
     *
     * @return
     */
    public List<Otable> selectAllTable() {
        OtableExample tableExample = new OtableExample();
        OtableExample.Criteria criteria = tableExample.createCriteria();
        criteria.andTableIdIsNotNull();
        List<Otable> tableList = tableMapper.selectByExample(tableExample);
        return tableList;
    }

    /**
     * 通过餐桌id查询餐桌
     *
     * @param tableId
     * @return
     */
    public Otable selectSingleTable(int tableId) {
        return tableMapper.selectByPrimaryKey(tableId);
    }

    /**
     * 查询所有空闲餐桌
     *
     * @return
     */
    @Override
    public List<Otable> selectNoStatusTable() {
        // 创建筛选器的对象【实例】
        OtableExample otableExample = new OtableExample();
        // 创建筛选器
        OtableExample.Criteria criteria = otableExample.createCriteria();
        // 给筛选器一定的条件，封装到实例中
        criteria.andTableStatusEqualTo(0);
        List<Otable> otables = tableMapper.selectByExample(otableExample);
        return otables;
    }

    /**
     * 查询所有服务中的餐桌
     *
     * @return
     */
    @Override
    public List<Otable> selectStatusTable() {
        // 创建筛选器的对象【实例】
        OtableExample otableExample = new OtableExample();
        // 创建筛选器
        OtableExample.Criteria criteria = otableExample.createCriteria();
        // 给筛选器一定的条件，封装到实例中
        criteria.andTableStatusEqualTo(1);
        List<Otable> otables = tableMapper.selectByExample(otableExample);
        return otables;
    }


    /**
     * 查询餐桌名称
     *
     * @param tableId
     * @return
     */
    public String selectTablesNameByTabId(int tableId) {
        Otable table = tableMapper.selectByPrimaryKey(tableId);
        return table.getoTableName();
    }

    /**
     * 查询餐桌消费信息
     *
     * @param tableId
     * @return
     */
    public String selectFoodsByTabId(int tableId) {
        Otable table = tableMapper.selectByPrimaryKey(tableId);
        return table.getTableDesc();
    }

    /**
     * 餐桌入座，状态改为服务
     *
     * @return
     */
    public String insertTables() {
        return null;
    }
}
